package com.timeset.activity.service;

import com.timeset.activity.entity.*;
import com.timeset.activity.mapper.ActivityMapper;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class ActivityServiceImpl {
    @Resource
    private ActivityMapper activityMapper;

    //根据userId,activities添加活动
    //根据userId,activities添加活动
   // public int addActivities(int organizationId,String title,String content,String label,String upTime,int viewNum){
       // return activityMapper.addActivities(organizationId,upTime,viewNum,content,label,title);
    //}
    public int addActivities(Activities activities){
        return activityMapper.addActivities(activities);
    }

    //查找所有活动
    public List<Activities> findAllActivities(int num,int schoolId){
        int pageIndex=num*3;
        return activityMapper.findAllActivities(pageIndex,schoolId);
    }
    //根据userId查找发布的活动
    public List<Activities> findActivitiesByOrganizationId(int id){
        return activityMapper.findActivitiesByOrganizationId(id);
    }

    //根据条件检索相关活动
    public  List<Activities> findActivitiesByLabel(String label){
        return activityMapper.findActivitiesByLabel(label);
    }

    //根据组织名搜索组织
    public List<Orgnaization> findOrganization(String name){
        return activityMapper.findOrganization(name);
    }
    //根据组织级别搜索活动
    public  List<Activities> findActivitiesByLevel(String level){
        return activityMapper.findActivitiesByLevel(level);
    }

    //根据 活动id删除活动
    public int deleteActivity(int id){
        return activityMapper.deleteActivity(id);
    }

    //设置活动参加人数
    public int joinNum(int aId,int total,int freeNum){
        return activityMapper.joinNum(aId, total, freeNum);
    }
    //删除活动参加人数
    public int deleteJoinNum(int aId){
        return activityMapper.deleteJoinNum(aId);
    }

    //
    //通过userId,aId查找申请表是否有该条申请
    public int isHaveApply(int aId,int userId){
        return activityMapper.isHaveApply(aId, userId);
    }
    //查询申请状态
    //查询申请状态0是未申请或者申请失败，1是提交申请，2申请成功，3是正在申请
    public int applyStatus(int aId,int userId){
        return activityMapper.applyStatus(aId, userId);
    }

    //活动申请参加的信息
    public ActivityApplyData activityApplyData(int aId){
        return activityMapper.activityApplyData(aId);
    }

    //设置活动申请参加的信息,当提交申请之前，即进入申请页面之前将活动正在申请人数加一，将空余位减一
    public int setApplyData(int aId,int a,int f){
        int  applyingNum=a+1;
        int freeNum=f-1;
        return activityMapper.setApplyData(aId, applyingNum, freeNum);
    }
    //准备申请参加活动
    public int toApplyToJoin(int aId,int userId,int applyResult){
        return activityMapper.toApplyToJoin(aId, userId,applyResult);
    }
    //申请参加活动
    public int applyToJoin(int aId,int userId,String answer,String currentTime){
        return activityMapper.applyToJoin(aId, userId,answer,currentTime);
    }
    //提交申请之后，成功申请参加活动，将正在申请人数减一，成功申请人数加一
    public int setApply(int aId,int a,int j){
        int  applyingNum=a-1;
        int joinNum=j+1;
        return activityMapper.setApply(aId, applyingNum, joinNum);
    }
    //当进入页面返回后或者取消申请时：将正在申请人数减一，空余位加一
    //取消申请：进入申请页面，点击返回或者超时造成页面关闭等finish操作，取消占位的同时删除apply表中的数据
    public int setCancelApplyData(int aId,int a,int f){
        int  applyingNum=a-1;
        int freeNum=f+1;
        return activityMapper.setCancelApplyData(aId, applyingNum, freeNum);

    }
    //取消申请：进入申请页面，点击返回或者超时造成页面关闭等finish操作，取消占位的同时删除apply表中的数据
    /*public int cancelApplyToJoin(int aId,int userId);*/
    public int cancelApplyToJoin(int aId,int userId){
        return activityMapper.cancelApplyToJoin(aId, userId);
    }


    //上传设置的问题表单
    public int upQuestionList(int aId,String questionList){
        return activityMapper.upQuestionList(aId, questionList);
    }
    //删除问题表单
    public int deleteQuestionList(int aId){
        return activityMapper.deleteQuestionList(aId);
    }
    //findQuestionByActivityId根据活动Id查询问题表单
    public String findQuestionByActivityId(int aId){
        return activityMapper.findQuestionByActivityId(aId);
    }




    /*
     * 历史活动
     *
     * */
    //根据组织id查找活动信息，根据每一个活动id查找活动申请信息
    public List<Activity> findHistoryActivityByOrgId(int oId){
        return activityMapper.findHistoryActivityByOrgId(oId);
    }
    //根据活动id修改活动状态：结束活动
    public int endActivityById(int aId){
        return activityMapper.endActivityById(aId);
    }
    //根据活动id查找活动
    public OnlyActivity findActivityById(int aId){
        return activityMapper.findActivityById(aId);
    }
    //根据活动id删除活动
    public int deleteActivityById(int aId){
        return activityMapper.deleteActivityById(aId);
    }

    public List<ApplyForm> findApplyInformationByAId(int aId){
        return  activityMapper.findApplyInformationByAId(aId);
    }
    //修改活动状态
    public int updateApplyStatus(int applyId,int status){
        return activityMapper.updateApplyStatus(applyId, status);
    }
    //修改活动失败：根据id查看是否还有申请数据
    public int isHaveApplyById(int applyId){
        return activityMapper.isHaveApplyById(applyId);
    }
    //根据id查看申请数据状态值
    public int findApplyStatusById(int applyId){
        return activityMapper.findApplyStatusById(applyId);
    }


}
